<template>
	<view class="search">
		<uni-search-bar @confirm="search" @input="input" v-model="key" placeholder="输入搜索的关键词"></uni-search-bar>
		<view class="recommend_search_hotkey">
			<view class="text">{{ i18n('搜索热词') }}</view>
			<custom-search-hotkey :item="hotkeys"></custom-search-hotkey>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			key: '',
			hotkeys: {}
		};
	},
	onLoad(ops) {
		this.key = ops.k;
		console.log(this.key)
		this.getHotKeysData();
	},
	methods: {
		i18n(v) {
			return this.$t('index')[v];
		},
		search(v) {
			uni.navigateTo({
				url:'../search/q?k='+v.value
			})
		},
		input(v) {
			console.log(v);
		},
		getHotKeysData() {
			let that = this;
			this.$store
				.dispatch('getHotKeysData', {})
				.then(res => {
					that.hotkeys = { data: res.data };
				})
				.catch(err => {
					console.log(err);
				})
				.finally(() => {});
		}
	}
};
</script>

<style lang="less">
.search {
	.recommend_search_hotkey {
		margin: 10rpx 20rpx;
		.text {
			padding: 10rpx 0 20rpx 0;
			color: #999;
			font-size: 28rpx;
		}
	}
}
</style>
